package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.junit.jupiter.api.AfterAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 护理等级
 */

@Api(tags = "护理等级")
@RestController
@RequestMapping("//nursingLevel")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级
     * @return
     */
    @ApiOperation("查询所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult<NursingLevelVo> getAllLeval() {
        return ResponseResult.success(nursingLevelService.getAllLeval());
    }

    /**
     * 新增
     * @param nursingLevelDto
     * @return
     */
    @ApiOperation("新增")
    @PostMapping("/insert")
    public ResponseResult addLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.addLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 条件分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation("条件分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> getPage(
                                                                 String name,
                                                                 Integer status,
                                                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
       PageResponse<NursingLevelVo> pageVo =  nursingLevelService.getPage(name,status,pageNum,pageSize);
       return ResponseResult.success(pageVo);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 修改
     * @param nursingLevelDto
     * @return
     */
    @ApiOperation("修改")
    @PutMapping("/update")
    public ResponseResult updateLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.updateLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public ResponseResult delLevel(@PathVariable Long id){
        nursingLevelService.delLevel(id);
        return ResponseResult.success();
    }

    /**
     * 启用禁用
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id,
                                       @PathVariable Integer status){
        nursingLevelService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
